package com.itheima.service.Impl;

import com.itheima.common.utils.ValidateCodeUtils;
import com.itheima.service.ValidateCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ValidateCodeServiceImpl implements ValidateCodeService {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 发送预约验证码
     * @param telephone
     */
    public void send4Order(String telephone) {
        Integer validateCode = ValidateCodeUtils.generateValidateCode(4);
        redisTemplate.opsForValue().set("order_"+telephone,validateCode.toString(),5, TimeUnit.MINUTES);

    }

    /**
     * 发送登录验证码
     * @param telephone
     */
    public void send4Login(String telephone) {
        Integer validateCode = ValidateCodeUtils.generateValidateCode(4);
        redisTemplate.opsForValue().set("login_"+telephone,validateCode.toString(),5, TimeUnit.MINUTES);
    }
}
